home *** CD-ROM | disk | FTP | other *** search
/ Disc to the Future 2 / Disc to the Future Part II Programmer's Reference (Wayzata Technology)(6013)(1992).bin / MAC / THINKC / 4_0 / FIX_DESK / SOURCE / UTILITY.C < prev    next >
C/C++ Source or Header  |  1988-09-07  |  3KB  |  141 lines

  1. #include <MacTypes.h>
  2. #include <QuickDraw.h>
  3. #include <WindowMgr.h>
  4. #include <ControlMgr.h>
  5. #include <DialogMgr.h>
  6. #include <EventMgr.h>
  7. #include <ToolboxUtil.h>
  8.  
  9. #include "fix.h"
  10.  
  11. #define    WATCH_CURSOR 4
  12.  
  13.     /* Get an item handle from a dialog. */
  14.  
  15. Handle get_item(the_dialog,item)
  16.     DialogPtr the_dialog;
  17.     int item;
  18. {
  19.     Handle the_item;
  20.     int type;
  21.     Rect box;
  22.  
  23.     GetDItem(the_dialog, item, &type, &the_item, &box);
  24.     return(the_item);
  25. }
  26.  
  27.     /* Set the cursor to the watch. */
  28.  
  29. void set_watch_cursor()
  30. {
  31.     SetCursor(*GetCursor(WATCH_CURSOR));
  32. }
  33.  
  34.     /* Set the cursor to the arrow. */
  35.  
  36. void set_normal_cursor()
  37. {
  38.     InitCursor();
  39. }
  40.  
  41.     /* Remove a resource from the current resource file. */
  42.  
  43. #ifndef TEST_MODE
  44.  
  45. void kill_resource(type, id)
  46.     long type;
  47.     int id;
  48. {
  49.     register Handle hand;
  50.  
  51.     SetResLoad(0);
  52.     hand = GetResource(type, id);
  53.     if (HomeResFile(hand) == CurResFile()) {
  54.         RmveResource(hand);
  55.         DisposHandle(hand);
  56.     }
  57.     else
  58.         ReleaseResource(hand);
  59.     SetResLoad(1);
  60. }
  61. #endif TEST_MODE
  62.  
  63.     /* Copy a Pascal-style string */
  64.  
  65. void copystr(dest, source)
  66.     register unsigned char *dest, *source;
  67. {
  68.     register int length;
  69.  
  70.     asm {
  71.         clr.w    length                ; Need full word for length
  72.         move.b    (source),length        ; Get length byte
  73. @0        move.b    (source)+,(dest)+    ; Copy a byte of the string
  74.         dbra    length,@0            ; Keep going until all done
  75.     }
  76. }
  77.  
  78.     /* Concatenate two Pascal-style strings into a third. */
  79.  
  80. void concatstr(first, second, dest)
  81.     register unsigned char *first, *second, *dest;
  82. {
  83.         /* Copy the first string to the destination (unless the same). */
  84.  
  85.     if (first != dest)
  86.         copystr(dest, first);
  87.  
  88.         /* If second string empty, just return. */
  89.  
  90.     if (second[0] == '\0')
  91.         return;
  92.  
  93.         /* If destination empty, just copy second to it. */
  94.  
  95.     if (dest[0] == '\0') {
  96.         copystr(dest, second);
  97.         return;
  98.     }
  99.  
  100.         /* Check that both strings will fit. */
  101.  
  102.     {
  103.         register int l1, l2;
  104.  
  105.         l1 = (unsigned char) first[0];
  106.         l2 = (unsigned char) second[0];
  107.         if ((l1 + l2) > 255)        /* doesn't fit! */
  108.             return;
  109.     }
  110.  
  111.         /* Copy the second string to the end of the destination. */
  112.  
  113.     {
  114.         register int length, first_length;
  115.  
  116.         asm {
  117.             clr.w    first_length            ; Get length of first string
  118.             move.b    (first),first_length    ; (may also be destination)
  119.             clr.w    length                    ; Get length of second string
  120.             move.b    (second),length
  121.             add.b    length,(dest)            ; Expand string to fit
  122.             adda.w    first_length,dest        ; Advance pointer forward
  123.             addq.w    #1,dest                    ; Past length byte, too...
  124.             addq.w    #1,second                ; Skip length byte
  125.             subq.w    #1,length                ; Skip it again
  126. @0            move.b    (second)+,(dest)+        ; Copy a byte
  127.             dbra    length, @0                ; Keep going until all done
  128.         }
  129.     }
  130. }
  131.  
  132.     /* Test two Pascal-style strings for equality */
  133.  
  134. int equalstr(s1, s2)
  135.     unsigned char *s1, *s2;
  136. {
  137.     /* Could call IUEqualString if wanted. */
  138.  
  139.     return (EqualString(s1, s2, FALSE, TRUE));
  140. }
  141.